import random


class Person:   # 人类
    def __init__(self, name, money):
        self.name = name
        self.money = money

    def speak(self):
        return f"抢红包成功，我是{self.name}，现在有{round(self.money, 2)}块钱"


class Manager(Person):  # 群主
    def __init__(self, name, money):
        super().__init__(name, money)
        self.red_packet = []

    def send(self, num: int, money: int):
        print(f"群主发拼手气红包啦，红包数为{num}，红包金额为{money}")

        if self.money - money < 0:
            return f"发红包失败，群主为{self.name}，余额不足，当前余额为{self.money}，所需要的金额为{num * money}"
        money1 = money

        for i in range(num):    # 最后一个红包获取剩下所有的钱
            if num - 1 == i:
                self.red_packet.append(round(money, 2))
                break

            while True:     # 保证每个红包都有钱
                red_packet_money = round(random.random() * money, 2)

                if money - red_packet_money >= ((num - 1 - i) * 0.01) and red_packet_money:
                    self.red_packet.append(red_packet_money)
                    money -= red_packet_money
                    break

        self.money -= money1
        return f"发红包成功，群主为{self.name}，发红包的金额为{money1}，当前余额为{self.money}"


class Member(Person):
    def get(self, manager):
        if manager.red_packet:      # 还有红包
            money = manager.red_packet.pop()

            self.money += money
            return super().speak()
        return f"红包已经被抢完了，我是{self.name}"


if __name__ == "__main__":
    manager = Manager("群主1", 100)

    member1 = Member("Tom", 0)
    member2 = Member("Jie", 0)
    member3 = Member("Fky", 0)
    member4 = Member("Rit", 0)

    print(manager.send(3, 10))

    print(member1.get(manager))
    print(member2.get(manager))
    print(member3.get(manager))
    print(member4.get(manager))